{%extends 'show/iframe_base.html'%}

{%block content%}
<link class="dplayer-css" rel="stylesheet" href="https://cdn.staticfile.org/dplayer/1.25.0/DPlayer.min.css">
<script src="https://cdn.staticfile.org/dashjs/2.9.2/dash.all.min.js"></script>
<script src="https://cdn.staticfile.org/dplayer/1.25.0/DPlayer.min.js"></script>
<div id="dplayer"  style="width:100%;height:100%;"></div>
<script>
  $(function () {
      const dp = new DPlayer({
          container: document.getElementById('dplayer'),
          lang: 'zh-cn',
          video: {
              url: "{{url}}",
              type: 'auto'
          },
          autoplay: true
      });
      // 防止出现401 token过期
      var cnt=1;
      dp.on('error', function () {
          if(cnt<=3){
              console.log('获取资源错误，开始重新加载！');
              let last = dp.video.currentTime;
              dp.video.src = "{{url}}";
              dp.video.load();
              dp.video.currentTime = last;
              dp.play();
              cnt=cnt+1;
          }

      });
      // 如果是播放状态 & 没有播放完 每25分钟重载视频防止卡死
      setInterval(function () {
          if (!dp.video.paused && !dp.video.ended) {
              console.log('开始重新加载！');
              let last = dp.video.currentTime;
              dp.video.src = "{{url}}";
              dp.video.load();
              dp.video.currentTime = last;
              dp.play();
          }
      }, 1000 * 60 * 25)
  });
</script>
{%endblock content%}
